﻿using System;
using System.Data;
using System.Windows.Forms;
using Saturn.App.FormOper;
using Saturn.App.Common;

namespace Saturn.App
{
    public partial class FormDj : Form
    {
        int pageIndex = 1;
        int count = 0;
        int pageSize = 6;
        int pageCount = 1;

        public FormDj()
        {
            InitializeComponent();
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            MessageBox.Show("点检内容已提交");
            //if (pageIndex == pageCount || pageCount == 0)
            //{
            //    CommonSound.MessageBeep(CommonSound.Information);
            //    MessageBox.Show("当前是最后一页！", "Error");
            //    return;
            //}
            //else
            //{
            //    pageIndex++;
            //    DataBind();
            //}
        }

        private void btnPre_Click(object sender, EventArgs e)
        {
            #region 记录开始保养时的时间
            #endregion
            //生成保养单号 设备编号+日期+类型+序列号
            label5.Text = "103" + DateTime.Now.ToString("yyyyMMdd") + "2" + 002;
            
            //if (pageIndex == 1)
            //{
            //    CommonSound.MessageBeep(CommonSound.Information);
            //    MessageBox.Show("当前是第一页！", "Error");
            //    return;
            //}
            //pageIndex--;
            //DataBind();
        }


        private void FrmReciveList_Load(object sender, EventArgs e)
        {
            //this.txtsearch.Focus();
            //DataBind();
        }
        private void DataBind()
        {
            //lstdata.Items.Clear();
            //string strWhere = string.Format(" ReciveOrgCode in('{0}') ", UserLogin.OrgID.TrimEnd(',').Replace(",", "','"));
            //if (!string.IsNullOrEmpty(txtsearch.Text.Trim()))
            //{
            //    strWhere += " and m.BillCode like '%" + txtsearch.Text.Trim() + "%' ";
            //}
            //DataTable dt = DataInterface.GetBills(strWhere, pageSize, pageIndex, out count, (int)EnumClass.ProductScanStatus.Recive);

            //if (count % pageSize == 0)
            //{
            //    pageCount = count / pageSize;
            //}
            //else
            //{
            //    pageCount = (count / pageSize) + 1;
            //}
            //foreach (DataRow row in dt.Rows)
            //{
            //    ListViewItem lstItem = new ListViewItem();
            //    lstItem.SubItems[0].Text = row["BillCode"].ToString();
            //    lstItem.SubItems.Add(row["Counts"].ToString());
            //    lstItem.SubItems.Add(row["StatusCN"].ToString());
            //    lstdata.Items.Add(lstItem);
            //}
        }

        private void lstdata_ItemActivate(object sender, EventArgs e)
        {
            //if (this.lstdata.FocusedItem != null)
            //{
            //    FrmRecive frm = new FrmRecive(this.lstdata.FocusedItem.Text);
            //    if (frm.ShowDialog() == DialogResult.OK)
            //    {
            //        DataBind();
            //    }
            //}
        }

        private void txtsearch_KeyUp(object sender, KeyEventArgs e)
        {
            DataBind();
        }

        private void btnReturn_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == (char)13 && !string.IsNullOrEmpty(textBox1.Text))
            {
                //设备名称
                label8.Text = "灌装系统";

            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (this.listBox1.SelectedIndex >= 0)
            {
                if (!this.listBox2.Items.Contains(this.listBox1.SelectedItem))
                {
                    this.listBox2.Items.Add(this.listBox1.SelectedItem);
                }
                else
                {
                    MessageBox.Show("无法重复添加");
                }
            }
            else
            {
                MessageBox.Show("选择要添加的点检内容");
            }            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (this.listBox2.SelectedIndex >= 0)
            {
                this.listBox2.Items.Remove(this.listBox2.SelectedItem);
            }
            else
            {
                MessageBox.Show("请选择要删除的点检项目");
            }
        }

    }
}